﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit.HTMLEditor;
using smartphone.App_Code;

namespace smartphone.UserControls
{
    public partial class CommentForm : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtPostComment_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                LabelComment.Text = "Bạn cần nhập đầy đủ thông tin hợp lệ.";
            }
            else
            {
                string name = TxtName.Text;
                string email = TxtEmail.Text;
                string content = CommentContent.Text;

                Comment com = new Comment();
                //lay ma noi dung hien hang comment nay dinh voiw
                string contentID = "";
                if (Request.QueryString["ProductId"] != null)
                {
                    contentID = Request.QueryString["ProductId"].ToString();
                }
                else if (Request.QueryString["ProductId"] == null && Request.QueryString["NewsId"] != null)
                {
                    contentID = Request.QueryString["NewsId"].ToString();
                }

                com.CreateComment(email, name, content, Int32.Parse(contentID));

                Response.Redirect(Request.RawUrl);
                //TxtName.Text = "";
                //TxtEmail.Text = "";
                //CommentContent.Content = "";
            }
        }

        protected void CustomValidatorContent_ServerValidate(object source, ServerValidateEventArgs args)
        {
            try
            {
                string s = CommentContent.Text;
                if (s.Length < 50)
                {
                    args.IsValid = false;
                }
                else
                {
                    args.IsValid = true;
                }

            }
            catch
            {
                args.IsValid = false;
            }

        }

    }
}